/*
 * inotify-sync - a simple file synchronizer and file system watcher
 * Copyright (C) 2010-2011, inotify-sync developers and inotify-sync contributors
 * Copyright (C) 2010-2011, Cohesion Network Security Studio
 *
 * inotify-sync is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * inotify-sync is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with inotify-sync; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/*
 * FILE:			XmlLogger.h
 * USAGE:			---
 * DESCRIPTION:		---
 * OPTIONS:			---
 * REQUIREMENTS:	---
 * BUGS:			---
 * NOTES:			---
 * AUTHOR:			LI Yiwei (mail:leeyiw@gmail.com)
 * COMPANY:			---
 * VERSION:			1.0
 * CREATED:			Thu Sep  1 13:55:46 CST 2011
 * REVISION:		---
 */

#ifndef XMLLOGGER
#define XMLLOGGER

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <fcntl.h>
#include <time.h>
#include <sys/time.h>
#include <sstream>
#include <errno.h>

#include "Profile.h"
#include "Converter.h"
#include "Logger.h"
#include "Error.h"

extern Converter Conv;

using namespace std;

#define LOG_TAB_NAME	"inotify_sync_log"
#define EVENT_TAB_NAME	"event"

class XmlLogger : public Logger
{
public:
	XmlLogger(const Profile& profile);
	virtual ~XmlLogger();

	virtual void log_create_file(string abs_path);
	virtual void log_create_dir(string abs_path);
	virtual void log_delete(string abs_path);
	virtual void log_modify(string abs_path);
	virtual void log_moved_from(string abs_path,uint32_t cookie);
	virtual void log_moved_to(string abs_path,uint32_t cookie);
	virtual void log_move_inside(string src_path,
					string dest_path,
					uint32_t cookie);
protected:
private:
	void unlog_moved_from(string abs_path,uint32_t cookie);
	void log_time_prop(xmlNodePtr p_node);
	void save_xml();

	Profile profile;
	xmlDocPtr p_doc;
	xmlNodePtr p_root_node;
	xmlNodePtr p_cur_node;
};
#endif
